<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" v-for="item in goodsList" :key="item.id" class="goods-item">
      <img :src="item.picture" alt="" />
      <p class="name ellipsis">{{ item.name }}</p>
      <p class="desc ellipsis">{{ item.desc }}</p>
      <p class="price">&yen;{{ item.price }}</p>
    </RouterLink>
  </div>
</template>
<script>
import { ref, computed } from 'vue'
import { findHotGoods } from '@/api/goods'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  props: {
    hotType: {
      type: Number,
      default: 1
    }
  },
  setup(props) {
    const route = useRoute()
    const goodsList = ref([])
    //  * 获取热榜商品
    //  * @param {Number} id - 商品id
    //  * @param {Number} type - 1代表24小时热销榜 2代表周热销榜 3代表总热销榜
    //  * @param {Number} limit - 获取个数
    findHotGoods({ id: route.params.id, type: props.hotType, limit: 3 }).then(res => {
      goodsList.value = res.result
      // console.log('11', res)
    })

    // 热销榜标题
    const titleobj = {
      1: '24小时热销榜',
      2: '周热销榜',
      3: '总热销榜'
    }
    const title = computed(() => {
      return titleobj[props.hotType]
    })
    return {
      goodsList,
      title
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  .goods-item {
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;
    img {
      width: 160px;
      height: 160px;
    }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
}
</style>
